using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace GodSoft.Models.Mapping
{
    public class RoleMap : EntityTypeConfiguration<Role>
    {
        public RoleMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.RoleName)
                .IsRequired()
                .HasMaxLength(32);

            this.Property(t => t.Describe)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Role");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CreateUserID).HasColumnName("CreateUserID");
            this.Property(t => t.RoleName).HasColumnName("RoleName");
            this.Property(t => t.DelFlag).HasColumnName("DelFlag");
            this.Property(t => t.SubTime).HasColumnName("SubTime");
            this.Property(t => t.Describe).HasColumnName("Describe");

            // Relationships
            this.HasMany(t => t.UserInfoes)
                .WithMany(t => t.Roles)
                .Map(m =>
                    {
                        m.ToTable("UserInfoRole");
                        m.MapLeftKey("RoleID");
                        m.MapRightKey("UserID");
                    });


        }
    }
}
